#pragma once
#include "SymbolAdapter.h"
#include "CodeListAdapter.h"
#include "HttpClient.h"

class XRankListWnd : public XWnd {
  public:
    XRankListWnd();
    virtual ~XRankListWnd();
    
  public:
    BOOL OnInitDialog(HWND wndFocus, LPARAM lInitParam);
    
  protected:
    void OnTimer(UINT_PTR idEvent);
    
  protected:
    virtual void OnLogin();
    virtual void OnLogout();
    
    virtual void OnReqData();
    virtual void OnDelData();
    
    bool OnHScroll(SOUI::EventScroll *pEvt);
    bool OnVScroll(SOUI::EventScroll *pEvt);
    
    bool OnItemHover(SOUI::EventItemPanelHover *pEvt);
    bool OnItemLeave(SOUI::EventItemPanelLeave *pEvt);
    
    bool OnItemHeaderSwap(SOUI::EventHeaderItemSwap *pEvt);
    bool OnItemDBClick(SOUI::EventLVItemDBClick *pEvt);
    
    bool OnItemSelChanged(SOUI::EventLVSelChanged *pEvt);
    bool OnEventCtxMenu(SOUI::EventCtxMenu *pEvt);
    
    void OnSize(UINT type, SOUI::CSize sz);
    
  private:
    void syncScrollBar();
    bool reqData(int reqPage, int pageSize);
    
  public:
    // *INDENT-OFF*
    BEGIN_MSG_MAP_EX(XRankListWnd)
        MSG_WM_INITDIALOG(OnInitDialog)
        MSG_WM_TIMER(OnTimer)
        MSG_WM_SIZE(OnSize)
        CHAIN_MSG_MAP(XWnd)
        REFLECT_NOTIFICATIONS_EX()
    END_MSG_MAP()
    // *INDENT-ON*
  private:
    SymbolAdapter   m_symbolAdapter;
    CodeListAdapter m_codeListAdapter;
    
    SOUI::SMCListView *m_pListSymbol = nullptr;
    SOUI::SMCListView *m_pListView = nullptr;
    
    std::vector<uint32_t>             m_codes;
    int                               m_curPage = 1;
    bool                              m_in_request = false;
};
